package com.myhome.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myhome.mapper.TurnoverOrderMapper;
import com.myhome.domain.TurnoverOrder;
import com.myhome.service.TurnoverOrderService;
/**
*@Author QYiXin 
* @Date 2021 11 01 17 20
**/
@Service
public class TurnoverOrderServiceImpl extends ServiceImpl<TurnoverOrderMapper, TurnoverOrder> implements TurnoverOrderService{

    @Override
    public List<TurnoverOrder> findBySymbol(String symbol) {
        List<TurnoverOrder> list = this.list(new LambdaQueryWrapper<TurnoverOrder>().eq(symbol != null, TurnoverOrder::getSymbol, symbol).eq(TurnoverOrder::getStatus, 1).last("limit 50"));
        if (CollectionUtil.isEmpty(list)) {
            return Collections.emptyList();
        }
        return list;

    }

    @Override
    public Page<TurnoverOrder> findByPage(Page<TurnoverOrder> page, Long userId, String symbol, Integer type) {
        return null;
    }

    @Override
    public List<TurnoverOrder> getBuyTurnoverOrder(Long orderId, Long userId) {
        return list(new LambdaQueryWrapper<TurnoverOrder>().eq(TurnoverOrder::getOrderId, orderId)
                .eq(TurnoverOrder::getBuyUserId, userId)
        );
    }


    /**
     * 获取卖出订单的成交记录
     *
     * @param orderId
     * @return
     */
    @Override
    public List<TurnoverOrder> getSellTurnoverOrder(Long orderId,Long userId) {
        return list(new LambdaQueryWrapper<TurnoverOrder>().eq(TurnoverOrder::getOrderId, orderId)
                .eq(TurnoverOrder::getSellUserId, userId)
        );

    }

}
